﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;
using static ServiceCore.Tool.ES.Es_knowledge;

namespace Customer.Areas.Knowledge.Controllers
{
    [ApiController, Area("Knowledge"), Route("/knowledge/[action]")]
    public class knowledge_for_shareController : ControllerBase
    {
        private readonly Iknowledge_service _service;
        private readonly IToole_DI _tool;
        public knowledge_for_shareController(Iknowledge_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }
        /// <summary>
        /// 获取指定列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_knowledge_for_share(string id)
        {
            var result = _service.get_knowledge_for_share(id);
            return result;
        } 
        /// <summary>
        ///  标记已读
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel read_knowledge(string uid, string id)
        {
            var result = _service.read_knowledge(uid, id);
            return result;
        } 
        /// <summary>
        ///  获取用户ID
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_uid()
        {
            var result = new ResultObjModel() { code=0, msg="success", data =  _tool.di_user.USER == null ? "" : _tool.di_user.USER.uid };
            return result;
        }

        /// <summary>
        /// 查询知识库内指定ID文档
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_knowledge(string id)
        {
            var result = _service.get_knowledge(id);
            return result;
        }
    }
    [ApiController, Area("Knowledge"), Route("/knowledge/[action]"), Customer_Admin]
    public class knowledgeController : ControllerBase
    {
        private readonly Iknowledge_service _service;
        private readonly IToole_DI _tool;
        public knowledgeController(Iknowledge_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }
        /// <summary>
        /// 获取指定列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_list(string parent_id = "top")
        {
            var result = _service.get_list(parent_id);
            return result;
        }
        /// <summary>
        /// 获取知识库类型数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_alllist(string top_id = "")
        {
            var result = _service.get_alllist(top_id);
            return result;
        }
        /// <summary>
        /// 删除知识库类型数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel del_item(string type_id)
        {
            var result = _service.del_item(type_id);
            return result;
        }
        /// <summary>
        /// 保存知识库类型数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel save_item(knowledge_type Params)
        {
            var result = _service.save_item(Params);
            return result;
        }
        /// <summary>
        /// 变更位置
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel change_position(string change_type, string type_id)
        {
            var result = _service.change_position(change_type, type_id);
            return result;
        }
        /// <summary>
        /// 保存知识库类型数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel save_knowledge(knowledge_base Params)
        {
            var result = _service.save_knowledge(Params);
            return result;
        }
        /// <summary>
        /// 查询知识库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel knowledge_search(knowledge_search query)
        {
            var result = _service.knowledge_search(query);
            return result;
        }
        /// <summary>
        /// 查询面向所有人的知识库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel knowledge_search_to_public(knowledge_search query)
        {
            var result = _service.knowledge_search_to_public(query);
            return result;
        }
       

        /// <summary>
        /// 删除知识库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel del_knowledge(string id)
        {
            var result = _service.del_knowledge(id);
            return result;
        }

        /// <summary>
        /// 查询知识库内指定ID文档
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel change_knowledge_state(string id, int? state, DateTime? showtime = null)
        {
            var result = _service.change_knowledge_state(id, state, showtime);
            return result;
        }

        /// <summary>
        /// 开始分享
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel start_share(string id, bool? is_long, share_params? set_params)
        {
            var result = _service.start_share(id, is_long, set_params);
            return result;
        }

        /// <summary>
        /// 取消分享
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel cancel_share(string id)
        {
            var result = _service.cancel_share(id);
            return result;
        }
        /// <summary>
        /// 获取看板首页详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_kanban_index(string type_id)
        {
            var result = _service.get_kanban_index(type_id);
            return result;
        } 
        /// <summary>
        /// 获取分页看板数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel get_kanban_pagelist(knowledge_search query)
        {
            var result = _service.get_kanban_pagelist(query);
            return result;
        }
        /// <summary>
        /// 关键字搜索
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel search_kanben_pagelist(knowledge_search query)
        {
            var result = _service.search_kanben_pagelist(query);
            return result;
        }
    }
}